<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var sortSentence = function (s) {
      s = s.split(' ')
      var arr = []
      s.forEach(font => {
        // 根据对应数字 - 1 ,添加到数组对应顺序下标
        // 赋值时候截取后面的一位数字
        arr[font[font.length - 1] - 1] = font.slice(0, font.length - 1)
      });
      return arr.join(' ')
    };
    console.log(sortSentence("is2 sentence4 This1 a3"));
  </script>

</body>

</html>